<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); 

class CI_Thor {
	
	var $columns;
	var $settings;
	var $keywords;
	var $CI;
    function __construct()
    {	
		$this->get_column();
		$this->get_settings();
    }
	
	function loginstate()
	{
		$CI =& get_instance();
		
		$LoggedIN = $CI->session->userdata('logged_in');
		
		if(! $LoggedIN)
		{
			echo '<script type="text/javascript"> top.location.href = "/mang/"; </script>';
			exit();
		}
	}
	
	function get_file($eURL)
	{
		$eFile = read_file('./cache/'.$eURL.'.db');
		
		if(! $eFile)
		  $eFile = FALSE;
		else
		  $eFile = unserialize($eFile);
		
		return $eFile;
	}
	
	function save_file($content, $path)
	{
		write_file('./cache/'.$path.'.db', serialize($content));
	}

	function get_column()
	{
		$CI =& get_instance();
		
		$eColumns = read_file('./cache/columns.db');
		
		if($eColumns == FALSE)
		{
			$CI->db->order_by('order', 'asc');
			$CI->db->order_by('id', 'asc');
			$CI->db->select('id, title, path');
			$eColumns = $CI->db->get('column')->result();
			write_file('./cache/columns.db', serialize($eColumns));
		}
		else $eColumns = unserialize($eColumns);
				
		$this->columns = $eColumns;
	}
	
	function get_settings()
	{
		$eSettings = read_file('./cache/settings.db');
		$CI =& get_instance();
		if($eSettings == FALSE)
		{
			$CI->db->select('s_id as id, s_title as title, s_phone as phone, s_fax as fax, s_email as email, s_mobile as mobile, s_address as address, s_hometitle as hometitle, s_htmlkeyword as htmlkeyword, s_htmldescribe as htmldescribe, s_smtphost as smtphost, s_smtpuser as smtpuser, s_smtppass as smtppass, s_smtpport as smtpport');
			$eSettings = $CI->db->get('settings')->row();
			write_file('./cache/settings.db', serialize($eSettings));
		}
		else $eSettings = unserialize($eSettings);

		$this->settings = $eSettings;
	}
}

?>
